package org.example.web;

import com.alibaba.fastjson.JSON;
import org.example.pojo.Ipfs;
import org.example.service.IpfsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/Query")
public class Query extends HttpServlet {

    IpfsService ipfsService = new IpfsService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //1.调用Service完成查询
        List<Ipfs> ipfsList = ipfsService.query();
        System.out.println("query");
        //将集合转换成JSON    序列化
        String s = JSON.toJSONString(ipfsList);
        System.out.println(s);
        //响应数据
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(s);
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);

    }
}

